import { Dimensions, StyleSheet, Text, View } from 'react-native'
import React, { useState } from 'react'
import { Input,  Switch, List, Button } from '@ant-design/react-native'
import axios from 'axios'
import { router } from 'expo-router'

export default function addAddress() {
    const addAddress = () => {
        axios.post(`http://192.168.13.227:3000/czz/addAddress`,{name,phone,address,fullAddress,isdefault})
        .then(res=>{
            router.back()
        })
    }
    const [name,setName]=useState('')
    const [phone,setPhone]=useState('')
    const [address,setAddress]=useState('')
    const [fullAddress,setFullAddress]=useState('')
    const [isdefault,setIsdefault]=useState(false)
  return (
    <View>
      <View>
        <List renderHeader="姓名">
            <List.Item>
            <Input value={name} onChangeText={setName} placeholder="收货人姓名" />
            </List.Item>
        </List>
        <List renderHeader="电话">
            <List.Item>
            <Input value={phone} onChangeText={setPhone} placeholder="收货人电话" />
            </List.Item>
        </List>
      </View>
      <View style={{marginTop:10}}>
        <List>
            <List.Item>
                <Input value={address} onChangeText={setAddress} placeholder="所在地区(省、市、区)" />
            </List.Item>
        </List>
        <List>
            <List.Item>
                <Input  value={fullAddress} onChangeText={setFullAddress} placeholder="详细地址(街道、门牌号等)" />
            </List.Item>
        </List>
      </View>
      <View style={{ backgroundColor:'#fff',marginTop:10,padding:10,flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center'}}>
        <Text>设置为默认地址</Text>
        <Switch checked={isdefault} onChange={setIsdefault} />
      </View>
      <Button  onPressIn={addAddress} type='primary' style={{width:Dimensions.get('window').width*0.9,alignItems:'center',height:Dimensions.get('window').height*0.05,marginTop:10,alignSelf:'center'}}>保存</Button>
    </View>
  )
}

const styles = StyleSheet.create({})